import {LogLanguage} from "../dist/index.js"

// 测试TID识别
const testCases = [
  // 标准TID格式
  "2024-01-15 10:30:45 [INFO] TID:abc123.def456.ghi789 [service.SBYBaseService:70] Processing request",
  
  // 没有TID:前缀的TID格式
  "2024-01-15 10:30:45 [INFO] [fcdfba1a21214a8e97c7d8fd1a8aa287.1161.17544505317727189] [service.SBYBaseService:70] Processing request",
  
  // 混合格式
  "2024-01-15 10:30:45 [ERROR] TID:abc123 [fcdfba1a21214a8e97c7d8fd1a8aa287.1161.17544505317727189] [service.SBYBaseService:70] Error occurred",
  
  // 只有没有前缀的TID
  "2024-01-15 10:30:45 [WARNING] [fcdfba1a21214a8e97c7d8fd1a8aa287.1161.17544505317727189] merId=1749611201012113",
  
  // 复杂格式
  "2024-01-15 10:30:45 [FATAL] [fcdfba1a21214a8e97c7d8fd1a8aa287.1161.17544505317727189] (com.cn.yft.ora.bank.sby.service.SBYBaseService:70) Critical error"
]

console.log("=== TID 识别测试 ===")

testCases.forEach((testCase, index) => {
  console.log(`\n测试 ${index + 1}:`)
  console.log(`输入: ${testCase}`)
  
  const tree = LogLanguage.parser.parse(testCase)
  let foundNodes = []
  
  tree.iterate({
    enter: (node) => {
      foundNodes.push({
        name: node.type.name,
        from: node.from,
        to: node.to,
        text: testCase.slice(node.from, node.to)
      })
    }
  })
  
  console.log("识别的节点:")
  foundNodes.forEach(node => {
    console.log(`  - ${node.name}: "${node.text}" (${node.from}-${node.to})`)
  })
  
  // 检查TID相关节点
  const tidNodes = foundNodes.filter(node => 
    node.name.includes('TID') || 
    (node.name === 'TIDExpression' && node.text.includes('fcdfba1a21214a8e97c7d8fd1a8aa287'))
  )
  
  if (tidNodes.length > 0) {
    console.log("✓ TID 节点识别成功")
    tidNodes.forEach(node => {
      console.log(`  - ${node.name}: "${node.text}"`)
    })
  } else {
    console.log("✗ 未找到 TID 节点")
  }
}) 